.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
.\" Portions Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2011 by Delphix.  All rights reserved.
.\"
.TH POSIX_SPAWN_PIPE_NP 3C "Oct 14, 2011"
.SH NAME
posix_spawn_pipe_np \- spawn a process with connected pipe
.SH SYNOPSIS
.LP
.nf
#include <spawn.h>

\fBint\fR \fBposix_spawn_pipe_np\fR(\fBpid_t *restrict\fR \fIpid\fR,
     \fBint *restrict\fR \fIfdp\fR,
     \fBconst char *restrict\fR \fIcmd\fR,
     \fBboolean_t\fR \fIwrite\fR,
     \fBconst posix_spawn_file_actions_t *\fR\fIfile_actions\fR,
     \fBconst posix_spawnattr_t *restrict\fR \fIattr\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBposix_spawn_pipe_np()\fR function creates a new process
(child process) to run \fBsh -c \fIcmd\fR\fR, and connects the new
process's standard input or output to a file descriptor.
.sp
.LP
The new process's environment (the \fIenviron\fR global variable) is
inherited from the current process.
.sp
.LP
The \fIcmd\fR argument is the string for the child shell process to execute.
.sp
.LP
If the \fIwrite\fR argument is set, the returned file descriptor will be
connected to the new process's standard input, and will be opened for
writing.  Otherwise, the file descriptor will be connected to the new
process's standard output, and will be opened for reading.
.sp
.LP
If \fIfile_actions\fR is not \fINULL\fR, then the file descriptors open
in the child process are those open in the calling process as modified
by the spawn file actions object pointed to by \fIfile_actions\fR and
the \fBFD_CLOEXEC\fR flag of each remaining open file descriptor after
the spawn file actions have been processed.  See \fBposix_spawn\fR(3C)
for details on the behavior of \fIfile_actions\fR.
.sp
.LP
If \fIattr\fR is not \fINULL\fR, then the signal mask, signal default or
ignore actions, and the effective user and group IDs for the child
process are changed as specified in the attributes object referenced by
\fIattr\fR.  See \fBposix_spawn\fR(3C) for details on the behavior of
\fIattr\fR.
.sp
.LP
All process attributes, other than those influenced by the attributes set in
the object referenced by \fIattr\fR as specified above or by the file
descriptor manipulations specified in \fIfile_actions\fR appear in the new
process image as though \fBfork()\fR had been called to create a child process
and then a member of the \fBexec\fR family of functions had been called by the
child process to execute \fB/bin/sh\fR.
.sp
.LP
The fork handlers are not run when \fBposix_spawn_pipe_np()\fR is called.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBposix_spawn_pipe_np()\fR returns the
process ID of the child process to the parent process in the variable
pointed to by a non-null \fIpidp\fR argument, returns the file
descriptor which is connected to the child process in the variable
pointed to by a non-null \fIfdp\fR argument, and returns zero as the
function return value. Otherwise, no child process is created, the value
stored into the variable pointed to by a non-null \fIpidp\fR and
\fIfdp\fR is unspecified, and an error number is returned as the
function return value to indicate the error.
.SH ERRORS
.sp
.LP
See \fBposix_spawn\fR(3C).

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR exec (2),
.BR fork (2),
.BR open (2),
.BR popen (3C),
.BR posix_spawn (3C),
.BR posix_spawn_file_actions_addclose (3C),
.BR posix_spawn_file_actions_adddup2 (3C),
.BR posix_spawn_file_actions_addopen (3C),
.BR posix_spawn_file_actions_destroy (3C),
.BR posix_spawn_file_actions_init (3C),
.BR posix_spawnattr_destroy (3C),
.BR posix_spawnattr_getflags (3C),
.BR posix_spawnattr_getpgroup (3C),
.BR posix_spawnattr_getschedparam (3C),
.BR posix_spawnattr_getschedpolicy (3C),
.BR posix_spawnattr_getsigdefault (3C),
.BR posix_spawnattr_getsigignore_np (3C),
.BR posix_spawnattr_getsigmask (3C),
.BR posix_spawnattr_init (3C),
.BR posix_spawnattr_setflags (3C),
.BR posix_spawnattr_setpgroup (3C),
.BR posix_spawnattr_setschedparam (3C),
.BR posix_spawnattr_setschedpolicy (3C),
.BR posix_spawnattr_setsigdefault (3C),
.BR posix_spawnattr_setsigignore_np (3C),
.BR posix_spawnattr_setsigmask (3C),
.BR system (3C),
.BR wait (3C),
.BR attributes (7),
.BR standards (7)
